import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sports_new/controller/service/config_service.dart';
import 'package:sports_new/resources/colours.dart';
import 'package:sports_new/resources/styles.dart';
import 'package:sports_new/utils/sound_utils.dart';
import 'package:sports_new/utils/widget_utils.dart';
import 'package:sports_new/widgets/base/qkd_widget.dart';

import '../../../widgets/base/qkd_text.dart';

class ZqSoundPage extends StatefulWidget {
  const ZqSoundPage({super.key});

  @override
  State<ZqSoundPage> createState() => _ZqSoundPageState();
}

class _ZqSoundPageState extends State<ZqSoundPage> {
  ConfigService configService = Get.find<ConfigService>();

  //0 主队 1客队
  int? type = Get.arguments;
  @override
  Widget build(BuildContext context) {
    List<Widget> widget = [];
    for (int index = 0; index < configService.soundName.length; index++) {
      widget.add(type == 0
          ? QkdWidget.selectCell(configService.soundName[index],
              configService.zqConfig.zqAlert3 == index,
              onTap: () => onTap(index))
          : QkdWidget.selectCell(configService.soundName[index],
              configService.zqConfig.zqAlert4 == index,
              onTap: () => onTap(index)));
      if (index != configService.soundName.length - 1) {
        widget.add(QkdWidget.seperateLine());
      }
    }
    return Scaffold(
      appBar: Styles.appBar(title: QkdText(type == 0 ? '主队进球声音' : '客队进球声音')),
      backgroundColor: Colours.scaffoldBg,
      body: ListView(children: [SizedBox(height: 10), ...widget]),
    );
  }

  onTap(int index) {
    if (type == 0) {
      configService.zqConfig.zqAlert3 = index;
      configService.update(
          ConfigType.zqAlert3, configService.zqConfig.zqAlert3);
      SoundUtils.playSoccerGoal(true);
    } else {
      configService.zqConfig.zqAlert4 = index;
      configService.update(
          ConfigType.zqAlert4, configService.zqConfig.zqAlert4);
      SoundUtils.playSoccerGoal(false);
    }
    update();
  }
}
